package com.lordjoe.collectiveintelligence.pricemodel;

import com.lordjoe.collectiveintelligence.data.*;

/**
 * com.lordjoe.collectiveintelligence.pricemodel.WinePriceModel
 *
 * @author Steve Lewis
 * @date May 12, 2009
 */
public class WinePriceModel implements IGeneratorModel
{
    public static WinePriceModel[] EMPTY_ARRAY = {};
    public static Class THIS_CLASS = WinePriceModel.class;

     public static WinePriceModel INSTANCE = new WinePriceModel();

    private WinePriceModel() {}
    /**
     * generate a value given a set of data
     *
     * @param generator
     * @return
     */
    public Object generateValue(IDataItem generator)
    {
        IMeasurement<Integer> ratingMeasure = generator.getMeasurement(WineModel.WineRating);
        IMeasurement<Integer> ageMeasure = generator.getMeasurement(WineModel.WineAge);
        int rating = ratingMeasure.getValue();
        int age = ageMeasure.getValue();
        int peak_age = rating - 50;

        double price = rating / 2;
        if(age > peak_age) {
            price = price * (5 - (age - peak_age));
        }
        else {
            price = price * (5 * (age + 1.0) / peak_age);
        }

        return new Double(Math.max(0,price));
    }
}
